package com.zm.dao;

import com.zm.domain.Account;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface IAccountDao {
    /**
     * 查询所有账户，并且获取每个账户所属的用户信息
     * @return
     */
    @Select("select * from account")
    @Results(id = "accountMap",value = {
            @Result(id= true,column = "id",property = "id"),
            @Result(column = "uid",property = "uid"),
            @Result(column = "money",property = "money"),                                                       //一对多查多用延迟加载
            @Result(property = "user",column = "uid",one = @One(select ="com.zm.dao.IUserDao.findById",fetchType = FetchType.LAZY))


    })
    List<Account> findAll();

    /**
     * 根据用户id查询账户信息(IUserDao中用户查询，并获取账户信息方法中要用到这个方法，上面“查询所有账户，并且获取每个账户所属的用户信息”亦是如此)
     * @param uid
     * @return
     */
    @Select("select * from account where uid=#{uid}")
    List<Account> findAccountByUid(Integer uid);
}
